﻿using Blog.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;

namespace Blog.Controllers
{
    
    public class EDGController : Controller
    {
        // GET: EDG
        public ActionResult Index()
        {
            using (UserEntities db= new UserEntities())
            {
                var user = db.Reg.ToList();
                return View(user);
            }
                
        }
        public ActionResult aa()
        {
            return View();
        }
        [HttpPost]
        public ActionResult Index(Reg user)
        {
            //判断账户密码是否正确 正确跳到首页
            using (UserEntities db =new UserEntities())
            {
                if (ModelState.IsValid)
                {
                    var u = db.Reg.FirstOrDefault(x => x.UserName == user.UserName && x.Passwoed == user.Passwoed);
                    if (u == null)
                    {
                        ModelState.AddModelError("","账号或密码错误！");
                    }
                    else
                    {
                        return RedirectToAction("Cad/" + u.Id, "Home");
                    }
                }

                return View();
               
            }
            

        }
    }
}